#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
#  Author: Shawn.Tan
#  Date : 2025.10.28
#
#  History : Initial Version 2025.10.28
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR
# FIT FOR A PARTICULAR PURPOSE.
# See the License for the specific language governing permissions and
# limitations under the License.
#
SIM_SRCS := SimLoader.cc SimApiBACKEND.cc
ALL_SRCS := $(SIM_SRCS)

OPTIMIZATION = -O2
include ../../utils/make/Makefile.common

ARCH_ENUM=GPGPU

INC_PATHS = -I. -I../../base/inc -I../../3rd_party/inc

NODEPS:=clean

vpath %.cc . ../../base/src
vpath %.d $(DEP_DIR)

all:
	@$(MAKE) make_dir
	@$(MAKE) ../../bin/SimApiBACKEND.so

ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
-include $(ALL_DEPS)
endif

$(DEP_DIR)/%.d: %.cc
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) $(INC_PATHS) -MM -MT '$(patsubst $(DEP_DIR)/%.d,$(OBJ_DIR)/%.o,$@)' $< -MF $@

$(OBJ_DIR)/%.o: %.cc %.d
	$(CC) -c $(CFLAGS) $(INC_PATHS) -fPIC -o $@ $<

../../bin/SimApiHANDCAR.so: $(ALL_OBJS)
	$(CC) -o $@ $^ $(LFLAGS) -shared -fPIC

.PHONY: make_dir
make_dir:
	@mkdir -p make_area make_area/obj make_area/dep

.PHONY: deps
deps:
	@echo 'dependency files made'

.PHONY: clean
clean:
	rm -rf make_area
	rm -f ../../bin/SimApiBACKEND.so
